home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / dvector.zip / VECTOR.C < prev    next >
C/C++ Source or Header  |  1993-08-11  |  4KB  |  209 lines

  1. /* Written by Cookie Monster    July 5th, 1993
  2.  *
  3.  * HEY!  DON'T BE A LAMER!  DON'T RIP CODE!
  4.  * IF YOU USE MY CODE OR MY IDEAS, GREET ME!
  5.  *
  6.  * No warranty is provided at all for any
  7.  * circumstance, and these files are public domain.
  8.  *
  9.  * I will not go into detail about any of this code.
  10.  * If you need help or want more information, then
  11.  * please write me.
  12.  *
  13.  * You can write to Cookie Monster at:
  14.  *
  15.  *            Justin Newman
  16.  *            PO Box 5724
  17.  *          Eugene, OR  97405-0724
  18.  *
  19.  * WE NEED DEMO GROUP MEMBERS!  GIVE US A CALL
  20.  * IF YOU WOULD LIKE TO JOIN OUR GROUP!
  21.  *
  22.  * Call    The Cookie Jar BBS at 5o3.345.563o
  23.  */
  24.  
  25. #include <stdlib.h>
  26. #include <dos.h>
  27.  
  28. #include "sincos.h"
  29. #include "text.h"
  30.  
  31. #define a_sin(a)    \
  32.     sintbl[a]
  33. #define a_cos(a)    \
  34.     costbl[a]
  35.  
  36. #define PointsN    4*4*4
  37.  
  38. /*
  39.  * each point is defined as x,y,z  (p[0]=x,p[1]=y,[2]=z)
  40.  */
  41.  
  42. int Points[PointsN*3];
  43.  
  44. int
  45. main()
  46. {
  47.      int ScreenWidth,ScreenHeight;
  48.      int PreXadd,PreYadd;
  49.      int PostXadd,PostYadd,PreZadd;
  50.      int Xt,Yt,Zt;
  51.      int X,Y,Z;
  52.      int Xtv,Ytv,Ztv;
  53.      int Xi,Yi,Zi;
  54.      int Xan,Yan,Zan;
  55.      int ScreenX,ScreenY;
  56.      int ThisDI,SaveDI[PointsN];
  57.      int Waited;
  58.      int Char,CharN;
  59.      int done,i,i1,i2,a;
  60.      long temp;
  61.      char c;
  62.  
  63.      /* make a cube vector full of dots */
  64.      for (i=0;i<4;i++)                     /* z */
  65.         {
  66.             for (i1=0;i1<4;i1++)        /* y */
  67.              {
  68.                 for (i2=0;i2<4;i2++)    /* x */
  69.                  {
  70.                     Points[i*(16*3)+i1*(4*3)+i2*3+0]=( -40)+i2*30;        /* x */
  71.                     Points[i*(16*3)+i1*(4*3)+i2*3+1]=( -40)+i1*30;        /* y */
  72.                     Points[i*(16*3)+i1*(4*3)+i2*3+2]=( -40)+ i*30;        /* z */
  73.                  }
  74.              }
  75.         }
  76.  
  77.      ScreenWidth=320;
  78.      ScreenHeight=200;
  79.  
  80.      PreXadd=PreYadd=0;PreZadd=-5000;
  81.      PostXadd=ScreenWidth/2+100;
  82.      PostYadd=ScreenHeight/2;
  83.  
  84.      Xan=Yan=Zan=0;
  85.      Xtv=Ytv=Ztv=0;
  86.      Xi=Yi=Zi=0;
  87.  
  88.      Waited=0;
  89.      done=0;
  90.  
  91.      asm    mov    ax,13h
  92.      asm    int    10h
  93.  
  94.      Xi=-1;
  95.      Yi=2;
  96.      Zi=-1;
  97.  
  98.      while (!done)
  99.         {
  100.          asm mov    ax,0a000h
  101.          asm mov    es,ax
  102.  
  103.          for (i=0;i<PointsN;i++)
  104.             {
  105.              X=Points[i*3+0];
  106.              Y=Points[i*3+1];
  107.              Z=Points[i*3+2];
  108.  
  109.              /* rotate on x-axis */
  110.              Yt=(Y*a_cos(Xan)-Z*a_sin(Xan)) >> NUMB;
  111.              Zt=(Y*a_sin(Xan)+Z*a_cos(Xan)) >> NUMB;
  112.              Y=Yt;
  113.              Z=Zt;
  114.  
  115.              /* rotate on y-axis */
  116.              Xt=(X*a_cos(Yan)-Z*a_sin(Yan)) >> NUMB;
  117.              Zt=(X*a_sin(Yan)+Z*a_cos(Yan)) >> NUMB;
  118.              X=Xt;
  119.              Z=Zt;
  120.  
  121.              /* rotate on y-axis */
  122.              Xt=(X*a_cos(Zan)-Y*a_sin(Zan)) >> NUMB;
  123.              Yt=(X*a_sin(Zan)+Y*a_cos(Zan)) >> NUMB;
  124.              X=Xt;
  125.              Y=Yt;
  126.  
  127.              X=X+Xtv;
  128.              Y=Y+Ytv;
  129.              Z=Z+Ztv;
  130.  
  131.              ScreenX=((X+PreXadd)<<8)/(Z+PreZadd)+PostXadd;
  132.              ScreenY=((Y+PreYadd)<<8)/(Z+PreZadd)+PostYadd;
  133.  
  134.              ThisDI=ScreenY*ScreenWidth+ScreenX;
  135.  
  136.              if (SaveDI[i] != -1)
  137.                 {
  138.                  _DI=SaveDI[i];
  139.  
  140.                  asm mov  al,0
  141.                  asm mov  es:[di],al
  142.  
  143.                  SaveDI[i]=-1;
  144.                 }
  145.  
  146.              if (ScreenX<0 || ScreenX>ScreenWidth-1)     continue;
  147.              if (ScreenY<0 || ScreenY>ScreenHeight-1) continue;
  148.  
  149.              _DI=ThisDI;
  150.  
  151.              asm mov  al,15
  152.              asm mov  es:[di],al
  153.  
  154.              SaveDI[i]=ThisDI;
  155.             }
  156.  
  157.             asm    mov    ah,1
  158.             asm    int    16h
  159.             asm    jz    nokey
  160.  
  161.             switch(getch())
  162.              {
  163.                 case '\x1b':
  164.                     done=1;
  165.                     break;
  166.              }
  167.  
  168. nokey:
  169.  
  170.             Waited++;
  171.             if (Waited>3)
  172.              {
  173.                 PostXadd-=(a_sin(PostXadd-ScreenWidth/2)*10)/256;
  174.                 if (PostXadd<ScreenWidth/2)
  175.                     PostXadd=ScreenWidth/2;
  176.                 if (PreZadd<-313)
  177.                     PreZadd+=(PreZadd/-313*45);
  178.                 if (PreZadd>-313) PreZadd=-313;
  179.  
  180.                 Xan=Xan+Xi;
  181.                 Yan=Yan+Yi;
  182.                 Zan=Zan+Zi;
  183.  
  184.                 if (Xan<0) { Xan=359; }
  185.                 if (Yan<0) { Yan=359; }
  186.                 if (Zan<0) { Zan=359; }
  187.  
  188.                 if (Xan>359) { Xan=0; }
  189.                 if (Yan>359) { Yan=0; }
  190.                 if (Zan>359) { Zan=0; }
  191.  
  192.                 Waited=0;
  193.              }
  194.  
  195.              /* keep it about the same on all systems */
  196.              delay(1);
  197.         }
  198.  
  199.      asm    mov    ax,03h
  200.      asm    int    10h
  201.  
  202.      asm    mov    ah,9
  203.      asm    mov    dx,offset text
  204.      asm    int    21h
  205.  
  206.      return 0;
  207. }
  208.  
  209.